package com.example.studentaihouduan.Controller;

import com.example.studentaihouduan.service.AIService;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.Map;

@RestController
@RequestMapping("/api/ai")
@RequiredArgsConstructor
@EnableCaching
public class AIController {

    private final AIService aiService;

    @PostMapping("/ask")
    public ResponseEntity<?> askQuestion(@RequestBody Map<String, String> request) {
        String question = request.get("question");
        if (question == null || question.isBlank()) {
            return ResponseEntity.badRequest().body("问题不能为空");
        }
        String answer = aiService.askAI(question);
        return ResponseEntity.ok(Collections.singletonMap("answer", answer));
    }
}